﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VirtualTerminalControl
{
    public partial class Form_find : Form
    {

        VirtualTerminal virtualTerminal = null;
        public Form_find(VirtualTerminal virtualTerminal)
        {
            InitializeComponent();
            this.virtualTerminal = virtualTerminal;
        }

        int FindIndex = -1;
        private void BTN_Find_Next_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                if (FindIndex == -1)
                {
                    if (radioButton1.Checked)
                    {
                        FindIndex = virtualTerminal.GetBufferCount;
                    }
                    else
                    {
                        FindIndex = 0;
                    }
                }
                else
                {
                    if (radioButton1.Checked)
                    {
                        FindIndex--;

                    }
                    else
                    {

                        FindIndex++;
                        if (FindIndex >= virtualTerminal.GetBufferCount)
                        {
                            FindIndex = 0;
                        }
                    }
                }
                if (!virtualTerminal.FindStr(textBox1.Text, this.radioButton1.Checked, ref FindIndex))
                {
                    MessageBox.Show("\"" + textBox1.Text + "\"" + " 没有找到", "文本查询:");
                }
                else
                {
                    // MessageBox.Show(FindIndex.ToString());
                }

            }

        }

        private void BTN_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BTN_Find_Next_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
                this.BTN_Find_Next.Enabled = false;
            }
        }
    }
}
